package com.example.demo.controller;

import com.example.demo.dto.AreaDto;
import com.example.demo.dto.CommonDto;
import com.example.demo.dto.UpdateAreaDto;
import com.example.demo.entity.Address;
import com.example.demo.model.Result;
import com.example.demo.service.AddressService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author Dfrus
 * @Date 2022/2/19 16:27
 **/
@RequestMapping("/adders")
@RestController
@AllArgsConstructor
public class AddressController {
    private AddressService addressService;

    @GetMapping("/{id}")
    public Result getAddress(@PathVariable Integer id){
        return Result.buildSuccess(addressService.findAddress(id));
    }

    @PostMapping("/{id}")
    public void appendArea(@PathVariable Integer id , @RequestBody AreaDto areaDto){
        areaDto.setUserId(id);
        addressService.findArea(areaDto);
    }

    @GetMapping("/amend/{id}")
    public Result getOne(@PathVariable Integer id){
        return Result.buildSuccess(addressService.findOne(id));
    }

    @PostMapping("/amend")
    public void updateArea(@RequestBody UpdateAreaDto updateAreaDto){
        addressService.updateFind(updateAreaDto);
    }

    @PostMapping("/common")
    public void updateCommon(@RequestBody CommonDto commonDto){
        addressService.updateCommon(commonDto);
    }
}
